package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SearchHotKey;
import com.ruoyi.system.service.ISearchHotKeyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 搜索热词Controller
 * 
 * @author ruoyi
 * @date 2021-09-30
 */
@RestController
@RequestMapping("/system/key")
public class SearchHotKeyController extends BaseController
{
    @Autowired
    private ISearchHotKeyService searchHotKeyService;

    /**
     * 查询搜索热词列表
     */
    @PreAuthorize("@ss.hasPermi('system:key:list')")
    @GetMapping("/list")
    public TableDataInfo list(SearchHotKey searchHotKey)
    {
        startPage();
        List<SearchHotKey> list = searchHotKeyService.selectSearchHotKeyList(searchHotKey);
        return getDataTable(list);
    }


    /**
     * 查询搜索热词列表
     */
    @PreAuthorize("@ss.hasPermi('system:key:list')")
    @GetMapping("/hots")
    public AjaxResult getHots()
    {
        List<SearchHotKey> list = searchHotKeyService.getHots();
        return AjaxResult.success(list);
    }

    /**
     * 导出搜索热词列表
     */
    @PreAuthorize("@ss.hasPermi('system:key:export')")
    @Log(title = "搜索热词", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SearchHotKey searchHotKey)
    {
        List<SearchHotKey> list = searchHotKeyService.selectSearchHotKeyList(searchHotKey);
        ExcelUtil<SearchHotKey> util = new ExcelUtil<SearchHotKey>(SearchHotKey.class);
        return util.exportExcel(list, "搜索热词数据");
    }

    /**
     * 获取搜索热词详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:key:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(searchHotKeyService.selectSearchHotKeyById(id));
    }

    /**
     * 新增搜索热词
     */
    @PreAuthorize("@ss.hasPermi('system:key:add')")
    @Log(title = "搜索热词", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SearchHotKey searchHotKey)
    {
        return toAjax(searchHotKeyService.insertSearchHotKey(searchHotKey));
    }

    /**
     * 修改搜索热词
     */
    @PreAuthorize("@ss.hasPermi('system:key:edit')")
    @Log(title = "搜索热词", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SearchHotKey searchHotKey)
    {
        return toAjax(searchHotKeyService.updateSearchHotKey(searchHotKey));
    }

    /**
     * 删除搜索热词
     */
    @PreAuthorize("@ss.hasPermi('system:key:remove')")
    @Log(title = "搜索热词", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(searchHotKeyService.deleteSearchHotKeyByIds(ids));
    }
}
